package com.bk.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bk.entity.RoleInfo;
import com.bk.mapper.GetRoleInfoListMapper;
import com.bk.util.ReturnUtil;
import com.bk.util.SerilizableObjectUtil;

@Service
public class GetRoleInfoListService {
	
	@Autowired
	private GetRoleInfoListMapper getRoleInfoListMapper;
	
	//获得所有角色
	public List<RoleInfo> getAllRoleInfoList(){
		return getRoleInfoListMapper.getAllRoleInfoList();
	}

	//获得所有未认证角色
	public List<RoleInfo> getAllNoRoleList() {
		return getRoleInfoListMapper.getAllNoRoleList();
	}

	//根据flag判断角色是激活还是移除
	public ReturnUtil<RoleInfo> updateRole(String roleAuths, int flag) {
		String[] arr = roleAuths.split(","); // 用,分割
		if(flag==1) {//激活
			int returnCode=getRoleInfoListMapper.getActiveRole(arr);
			return returnCode>0?new ReturnUtil<RoleInfo>(200,"激活角色成功",null):new ReturnUtil<RoleInfo>(400,"激活角色失败",null);
		}else {//移除
			int returnCode = getRoleInfoListMapper.removeRole(arr);
			return returnCode>0?new ReturnUtil<RoleInfo>(200,"移除角色成功",null):new ReturnUtil<RoleInfo>(400,"移除角色失败",null);
		}
	}
	//根据权限名获取角色信息
	public RoleInfo getRoleInfoByAuthority(String authority) {
		RoleInfo roleInfo=getRoleInfoListMapper.getRoleInfoByAuthority(authority);
		return roleInfo!=null?roleInfo:null;
	}
	
}
